from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QPlainTextEdit, QMessageBox


# def handle_calc():
#     info = textEdit.toPlainText()
#     print('统计按钮被点击了')
#     print(info)
#     QMessageBox.about(window, "统计结果", info)
#
#
# app = QApplication([])
#
# window = QMainWindow()
# window.resize(500, 400)
# window.move(300, 310)
# window.setWindowTitle("薪资统计")
#
# textEdit = QPlainTextEdit(window)
# textEdit.setPlaceholderText("请输入薪资表")
# textEdit.move(10, 25)
# textEdit.resize(300, 350)
#
# button = QPushButton("统计", window)
# button.move(380, 80)
# button.clicked.connect(handle_calc)
#
# window.show()
#
# app.exec_()


class Stats:
    def __init__(self):
        # QMainWindow
        self.window = QMainWindow()
        self.window.resize(500, 400)
        self.window.move(300, 300)
        self.window.setWindowTitle('薪资统计')
        # QPlainTextEdit
        self.textEdit = QPlainTextEdit(self.window)
        self.textEdit.setPlaceholderText("请输入薪资表")
        self.textEdit.move(10, 25)
        self.textEdit.resize(300, 350)
        # QPushButton
        self.button = QPushButton('统计', self.window)
        self.button.move(380, 80)
        self.button.clicked.connect(self.handle_calc)

    def handle_calc(self):
        info = self.textEdit.toPlainText()
        # 薪资20000 以上 和 以下 的人员名单
        salary_above_20k = ''
        salary_below_20k = ''
        for line in info.splitlines():
            if not line.strip():
                continue
            parts = line.split(' ')
            # 去掉列表中的空字符串内容
            parts = [p for p in parts if p]
            name, salary, age = parts
            if int(salary) >= 20000:
                salary_above_20k += name + '\n'
            else:
                salary_below_20k += name + '\n'
        # QMessageBox
        QMessageBox.about(self.window,
                    '统计结果',
                    f'''薪资20000 以上的有：\n{salary_above_20k}
                    \n薪资20000 以下的有：\n{salary_below_20k}'''
                    )


if __name__ == '__main__':
    app = QApplication([])
    stats = Stats()
    stats.window.show()
    app.exec_()